package org.example.generator;

import java.util.concurrent.atomic.AtomicLong;

public class CustomerIdGenerator {
    private static final AtomicLong globalCounter = new AtomicLong(0);
    private static final long START_TIME = System.currentTimeMillis();

    /**
     * 生成唯一客户ID
     * 格式：相对时间戳(10位) + 线程ID(3位) + 全局计数器(10位)
     */
    public static long generateCustomerId() {
        long relativeTime = (System.currentTimeMillis() - START_TIME) / 1000; // 秒级时间戳
        long threadId = Thread.currentThread().getId() % 1000; // 3位线程ID
        long counter = globalCounter.incrementAndGet() % 10000000000L; // 10位计数器

        return 1000000000000000L + relativeTime * 10000000000000L + threadId * 10000000000L + counter;
    }
}
